﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CommonLib;
using Project1.Model;
using Project1.View;
using System.Windows;
using System.Collections.ObjectModel;
using GalaSoft.MvvmLight.Messaging;
using GalaSoft.MvvmLight;
namespace Project1.ViewModel
{

    public class ModelMeasureFactoryVM : ViewModelBase
    {
        private CoreViewModel coreVM;
        private UserControlPoint ucPoint;
        private UserControlLine ucLine;
        private UserControlCircle ucCircle;
        private UserControlTemplate ucTemplate;
        private UserControlElementsList ucElementList;
        private UserControlHalConWindow halconWindow;
        private UserControlSelectionCard selectionCard;
        private Action hiddenAct,openAct;
        public ModelMeasureFactoryVM()
        {
            InitModel();
        }

        private void  InitModel()
        {
            coreVM = new CoreViewModel();
            Messenger.Default.Register<int>(this, "MeasureType", InitDefaultName);
            Messenger.Default.Register<Action>(this, "HiddenCard", SetHiddenCardAction);
            Messenger.Default.Register<Action>(this, "OpenCard", SetOpenCardAction);
            InitMain();
           
        }


        private void SetOpenCardAction(Action action)
        {
            openAct = action;
        }
        private void SetHiddenCardAction(Action action)
        {
            hiddenAct = action;
        }


        private void OnWindownClose(int msg)
        {
            coreVM.OnWindowClose();
        }
        private void InitDefaultName(int msg)
        {
            if (coreVM.CORE.ModelID == null)
            {
                var result = MessageBox.Show("请先加载模板！", "提示", MessageBoxButton.OK);
                return;
            }
            coreVM.CORE.SetMeasureMode(true);
           
            switch (msg)
            {
             
                case ConstValue.MEASURE_POINT_PEAK:
                    V3.ViewContent = ucPoint;
                    coreVM.CORE.SetDrawMode(true);
                    break;
                case ConstValue.MEASURE_POINT:
                    V3.ViewContent = ucPoint;
                    coreVM.CORE.SetDrawMode(true);
                    break;
                case ConstValue.MEASURE_LINE:
                    V3.ViewContent =ucLine;
                    coreVM.CORE.SetDrawMode(true);
                    break;
                case ConstValue.MEASURE_LINE_PEAK:
                    V3.ViewContent = ucLine;
                    coreVM.CORE.SetDrawMode(true);
                    break;
                case ConstValue.MEASURE_CIRCLE:
                    V3.ViewContent = ucCircle;
                    coreVM.CORE.SetDrawMode(true);
                    break;
                case ConstValue.MEASURE_LL_Cross:
                    V3.ViewContent = ucTemplate;
                    break;//线线交点
                case ConstValue.MEASURE_LC_Cross:
                    V3.ViewContent = ucTemplate;
                    break; //线圆交点
                case ConstValue.MEASURE_CC_Cross:
                    V3.ViewContent = ucTemplate;
                    break;//圆圆交点
                case ConstValue.MEASURE_P_Mid:
                    V3.ViewContent = ucTemplate;
                    break;
                case ConstValue.MEASURE_LL_Mid:
                    V3.ViewContent = ucTemplate;
                    break;//平分线
                case ConstValue.MEASURE_PL_Mid:
                    V3.ViewContent = ucTemplate;
                    break;//点线中线
                case ConstValue.MEASURE_PP_Mid:
                    V3.ViewContent = ucTemplate;
                    break;//点点中线
                case ConstValue.MEASURE_PL_VERTICAL:
                    V3.ViewContent = ucTemplate;
                    break;//垂线
                case ConstValue.MEASURE_PL_Parallel:
                    V3.ViewContent = ucTemplate;
                    break; //平行线
                case ConstValue.MEASURE_P_FitLine:
                    V3.ViewContent = ucTemplate;
                    break;//拟合直线
                case ConstValue.MEASURE_LL_Concate:
                    V3.ViewContent = ucTemplate;
                    break;
                case ConstValue.MEASURE_LL_InnerC:
                    V3.ViewContent = ucTemplate;
                    break;//内切圆
                case ConstValue.MEASURE_CC_Mid:
                    V3.ViewContent = ucTemplate;
                    break; //中间圆
                case ConstValue.MEASURE_C_SUP:
                    V3.ViewContent = ucTemplate;
                    break;//辅助圆
                case ConstValue.MEASURE_C_Fit:
                    V3.ViewContent = ucTemplate;
                    break;//近似圆
                case ConstValue.MEASURE_C_Center:
                    V3.ViewContent = ucTemplate;
                    break;//圆心
                case ConstValue.MEASURE_Arc_Concat:
                    V3.ViewContent = ucTemplate;
                    break; ; //弧线的结合
                case ConstValue.MEASURE_PP_DIST:
                    V3.ViewContent = ucTemplate;
                    break; //点点距离
                case ConstValue.MEASURE_PL_DIST:
                    V3.ViewContent = ucTemplate;
                    break;//点线距离
                case ConstValue.MEASURE_LL_Dist:
                    V3.ViewContent = ucTemplate;
                    break;//线线距离
                case ConstValue.MEASURE_PC_DIST:
                    V3.ViewContent = ucTemplate;
                    break;//点圆距离
                case ConstValue.MEASURE_LC_DIST:
                    V3.ViewContent = ucTemplate;
                    break;//线圆距离
                case ConstValue.MEASURE_CC_DIST:
                    V3.ViewContent = ucTemplate;
                    break;//圆圆距离
                case ConstValue.MEASURE_C_RADIUS:
                    V3.ViewContent = ucTemplate;
                    break;//圆径
                case ConstValue.MEASURE_ARC_ANGLE:
                    V3.ViewContent = ucTemplate;
                    break;//弧度
                case ConstValue.MEASURE_LL_ANGLE:
                    V3.ViewContent = ucTemplate;
                    break;//线夹角度
            }
            hiddenAct.Invoke();
            coreVM.CORE.SetCallBackAction(BackToSelectionCard);
            coreVM.CORE.GetDefaultName(msg);
        }
     

        private readonly int  COMP_CIRCLE = 0;
        private readonly int  COMP_LINE = 1;
        private readonly int  COMP_POINT = 2;
        private readonly int  COMP_WINDOW = 3;
        private readonly int  COMP_SELECTION_CARD = 4;
        private readonly int  COMP_ELEMENT_LIST = 5;
        private readonly int  COMP_PEAK_POINT = 6;
        private readonly int  COMP_PEAK_LINE = 7;
        private void  InitMain()
        {
            ucPoint = new UserControlPoint() { DataContext = coreVM };
            ucLine = new UserControlLine() { DataContext = coreVM };
            ucCircle = new UserControlCircle() { DataContext = coreVM};
            ucTemplate = new UserControlTemplate() { DataContext = coreVM };
            ucElementList = new UserControlElementsList() { DataContext = coreVM };
            halconWindow = new UserControlHalConWindow() { DataContext = coreVM };
           // coreVM.CORE.SetWindowHandle(halconWindow.hSmartWindowControlWPF1.HalconWindow);
            selectionCard = new UserControlSelectionCard() { DataContext = this };
            
            AllViewList = new ObservableCollection<ItemModel>
            {
                new ItemModel(){ NameStr = "圆",ViewContent= ucCircle},
                new ItemModel(){ NameStr = "线",ViewContent = ucLine},
                new ItemModel(){NameStr = "点",ViewContent = ucPoint},
                new ItemModel(){NameStr = "窗口",ViewContent = halconWindow},
                new ItemModel(){NameStr = "选项卡",ViewContent = selectionCard},
                new ItemModel(){NameStr = "要素显示列",ViewContent = ucElementList},
                new ItemModel(){ NameStr = "峰值点",ViewContent= ucCircle},
                new ItemModel(){ NameStr = "峰值线",ViewContent= ucCircle},
            };
            V1 = AllViewList[COMP_WINDOW];
            V3 = AllViewList[COMP_SELECTION_CARD];
            V4 = AllViewList[COMP_ELEMENT_LIST];
        }



        private void BackToSelectionCard()
        {

            V3.ViewContent = selectionCard;
            openAct.Invoke();
            //Messenger.Default.Send<string>("dispSelectionCard", "CallBack");
        }
        private ObservableCollection<ItemModel> _allViewList;
        /// <summary>
        /// 界面集合
        /// </summary>
        public ObservableCollection<ItemModel> AllViewList
        {
            get { return _allViewList; }
            set { _allViewList = value; RaisePropertyChanged(() => AllViewList); }
        }


        private ItemModel _V1;
        /// <summary>
        /// 选择的项
        /// </summary>
        public ItemModel V1
        {
            get { return _V1; }
            set { _V1 = value; RaisePropertyChanged(() => V1); }
        }

        private ItemModel _V2;
        /// <summary>
        /// 选择的项
        /// </summary>
        public ItemModel V2
        {
            get { return _V2; }
            set { _V2 = value; RaisePropertyChanged(() => V2); }
        }

        private ItemModel _V3;
        /// <summary>
        /// 选择的项
        /// </summary>
        public ItemModel V3
        {
            get { return _V3; }
            set { _V3 = value; RaisePropertyChanged(() => V3); }
        }

        private ItemModel _V4;
        /// <summary>
        /// 选择的项
        /// </summary>
        public ItemModel V4
        {
            get { return _V4; }
            set { _V4 = value; RaisePropertyChanged(() => V4); }
        }




    }
}
   

